#ifndef __QTOSG_EVENTADAPTER_H__
#define __QTOSG_EVENTADAPTER_H__

/*!
 *	@brief	mapping the key/mouse event of OpenSceneGraph to Qt.
 *	@author	pezy
 *	@date	2016-08-05
 *	@see
 */

#include <unordered_map>
#include <QtWidgets/QOpenGLWidget>
#include <QtGui/QInputEvent>
#include <osgViewer/GraphicsWindow>
#include <osgGA/GUIEventAdapter>

class QtOSGEventAdapterWidget : public QOpenGLWidget
{
public:
	QtOSGEventAdapterWidget(QWidget *parent = 0, Qt::WindowFlags f = 0);
	~QtOSGEventAdapterWidget();

protected:
	void resizeGL(int w, int h) override;
	void keyPressEvent(QKeyEvent* event) override;
	void keyReleaseEvent(QKeyEvent* event) override;
	void mousePressEvent(QMouseEvent* event) override;
	void mouseReleaseEvent(QMouseEvent* event) override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void mouseDoubleClickEvent(QMouseEvent *event) override;
	void wheelEvent(QWheelEvent* event) override;

private:
	void _setKeyboardModifiers(QInputEvent* event);
	osgGA::EventQueue* getEventQueue() const;

protected:
	osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _graphicsWindowEmbedded;

private:
	static std::unordered_map<int, int> key_map_;
	qreal device_pixel_ratio_;
};

#endif // __QTOSG_EVENTADAPTER_H__
